/*
 * 本类作用：mina框架：IoFilterAdapter（上一步：mina启动StartServer，下一步：mina框架过滤器MinaServerIOHandler）
 * 
 * 作者：袁小杰
 * 博客：http://blog.csdn.net/undoner
 * GIT：https://git.oschina.net/undoner
 * QQ：15137281
 * 
 */
package com.smforj.ssm.mina.server;

import org.apache.log4j.Logger;
import org.apache.mina.core.filterchain.IoFilterAdapter;
import org.apache.mina.core.filterchain.IoFilterChain;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.core.write.WriteRequest;

// 用于判断数据合法性
/***
 * 进行数据合法全检测
 * 
 * @author ghj
 * 
 */
public class MinaServerIOFilter extends IoFilterAdapter {

	static Logger log = Logger.getRootLogger();

	public MinaServerIOFilter() {
		log.debug(this.getClass().getName() + "：IOFilterFilter");
	}

	/**
	 * messageReceived，之后转到handler 进行数据处理
	 * */
	public void messageReceived(NextFilter nextFilter, IoSession session,
			Object message) throws Exception {
		log.debug(this.getClass().getName() + "：messageReceived"); 

		nextFilter.messageReceived(session, message);
	}

	@Override
	public void destroy() throws Exception {
		log.debug(this.getClass().getName() + "：destroy");
	}

	@Override
	public void exceptionCaught(NextFilter nextFilter, IoSession session,
			Throwable cause) throws Exception {
		log.debug(this.getClass().getName() + "：exceptionCaught");
		nextFilter.exceptionCaught(session, cause);
	}

	@Override
	public void filterClose(NextFilter nextFilter, IoSession session)
			throws Exception {
		log.debug(this.getClass().getName() + "：filterClose");
		nextFilter.filterClose(session);

	}

	@Override
	public void filterWrite(NextFilter nextFilter, IoSession session,
			WriteRequest writeRequest) throws Exception {
		log.debug(this.getClass().getName() + "：filterWrite");
		nextFilter.filterWrite(session, writeRequest);
	}

	@Override
	public void init() throws Exception {
		log.debug(this.getClass().getName() + "：init");
	}

	@Override
	public void messageSent(NextFilter nextFilter, IoSession session,
			WriteRequest writeRequest) throws Exception {
		log.debug(this.getClass().getName() + "：messageSent");
		nextFilter.messageSent(session, writeRequest);
	}

	@Override
	public void onPostAdd(IoFilterChain parent, String name,
			NextFilter nextFilter) throws Exception {
		log.debug(this.getClass().getName() + "：onPostAdd");
	}

	@Override
	public void onPostRemove(IoFilterChain parent, String name,
			NextFilter nextFilter) throws Exception {
		log.debug(this.getClass().getName() + "：onPostRemove");
	}

	@Override
	public void onPreAdd(IoFilterChain parent, String name,
			NextFilter nextFilter) throws Exception {
		log.debug(this.getClass().getName() + "：onPreAdd");
	}

	@Override
	public void onPreRemove(IoFilterChain parent, String name,
			NextFilter nextFilter) throws Exception {
		log.debug(this.getClass().getName() + "：onPreRemove");
	}

	@Override
	public void sessionClosed(NextFilter nextFilter, IoSession session)
			throws Exception {
		log.debug(this.getClass().getName() + "：sessionClosed");
		nextFilter.sessionClosed(session);
	}

	@Override
	public void sessionCreated(NextFilter nextFilter, IoSession session)
			throws Exception {
		log.debug(this.getClass().getName() + "：sessionCreated");
		nextFilter.sessionCreated(session);
	}

	@Override
	public void sessionIdle(NextFilter nextFilter, IoSession session,
			IdleStatus status) throws Exception {
		log.debug(this.getClass().getName() + "：sessionIdle");
		nextFilter.sessionIdle(session, status);
	}

	@Override
	public void sessionOpened(NextFilter nextFilter, IoSession session)
			throws Exception {
		log.debug(this.getClass().getName() + "：sessionOpened");
		nextFilter.sessionOpened(session);
	}
}
